package com.atguigu.lease.web.admin.custom.config;

import com.atguigu.lease.web.admin.custom.converter.StringToBaseEnumConverterFactory;
import com.atguigu.lease.web.admin.custom.interceptor.AuthenticationInterceptor;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Package: com.atguigu.lease.web.admin.custom.config
 *
 * @Description:
 * @Author xiongkunYang
 * @Create 2025/4/30 13:55
 */
@SpringBootConfiguration
@RequiredArgsConstructor
public class WebMvcConfiguration implements WebMvcConfigurer {

    private final StringToBaseEnumConverterFactory converterFactory;
    private final AuthenticationInterceptor authenticationInterceptor;
    @Value("${admin.auth.path-patterns.include}")
    private String includePathPatterns;
    @Value("${admin.auth.path-patterns.exclude}")
    private String excludePathPatterns;

    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverterFactory(this.converterFactory);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(this.authenticationInterceptor)
                .addPathPatterns(includePathPatterns)
                .excludePathPatterns(excludePathPatterns);
    }
}